#include <stdio.h>

int isDigitSorted(int num) {
    int curr = 10;
    while (num != 0) {
        int digit = num % 10;
        num /= 10;
        if (digit > curr) { return 0; }
        curr = digit;
    }
    return 1;
}

int main() {
    int limit;
    scanf("%d", &limit);
    for (int i = limit; i >= 0; i--) {
        if (isDigitSorted(i)) {
            printf("%d", i);
            return 0;
        }
    }
    printf("0");
    return 0;
}